using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows.Data;
using Avinor.NET.Client.Windows;
using Machine.Specifications;

namespace Avinor.NET.Specs.Client.Windows
{
    public class when_filtering_an_airport_list
    {
        const string _filterText = "stavanger";
        static AvinorViewModel _viewModel;
        static ICollectionView _dataView;
        
        Establish context = () =>
        {
            _viewModel = new AvinorViewModel();
        };

        Because of = () =>
        {
            _viewModel.Filter = _filterText;
            _dataView = CollectionViewSource.GetDefaultView(_viewModel.Airports);

        };

        It should_return_only_one_airport = () =>
        {
            int count = 0;
            foreach (var item in _dataView)
            {
                count++;
            }
            count.ShouldEqual(1);
        };

        It should_return_Stavanger_airport = () =>
        {
            var enumerator = _dataView.GetEnumerator();
            enumerator.MoveNext();
            var airport = enumerator.Current as Airport;
            airport.Name.ShouldBeEqualIgnoringCase(_filterText);
        };


    }
}